package com.eqdd.yiqidian.ui.mine.unsure;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;

import com.eqdd.nextinputs.Scheme;
import com.eqdd.nextinputs.StaticScheme;
import com.eqdd.nextinputs.ValueScheme;
import com.eqdd.yiqidian.MineAuPerfectActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.AreaBean;
import com.eqdd.yiqidian.bean.EditBean;
import com.eqdd.yiqidian.bean.rebuild.InvitedListResultBean;
import com.eqdd.yiqidian.bean.rebuild.UserAuthInfoResultBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.http.JsonCallBack;
import com.eqdd.yiqidian.service.UserService;
import com.eqdd.yiqidian.ui.MineAuActivity;
import com.eqdd.yiqidian.ui.base.BaseMultiEditActivity;
import com.eqdd.yiqidian.utils.EncryptUtil;
import com.eqdd.yiqidian.utils.MultiChooseUtil;
import com.eqdd.yiqidian.utils.SPUtil;
import com.eqdd.yiqidian.utils.SingleChooseUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.ActionSheetDialog;
import com.eqdd.yiqidian.widget.ChooseAlertView;
import com.eqdd.yiqidian.widget.EditDialogFragment;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.model.Response;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import chihane.jdaddressselector.BottomDialog;
import chihane.jdaddressselector.ISelectAble;
import io.rong.imkit.widget.AlterDialogFragment;

public class MineAuPerfectActivity extends BaseMultiEditActivity {
    private static final int HEIGHT_POSITION = 0;
    private static final int WEIGH_POSITION = 1;
    private static final int BLOOD_POSITION = 2;
    private static final int CZODIA_POSITION = 3;
    private static final int BELIEF_POSITION = 4;
    private static final int ADRESS_POSITION = 5;
    private static final int MARRY_POSITION = 6;
    private static final int CONTRACT_NAME_POSITION = 7;
    private static final int CONTRACT_REALT_POSITION = 8;
    private static final int CONTRACT_TEL_POSITION = 9;
    private static final int GRAD_POSITION = 10;
    private static final int EDU_POSITION = 11;
    private static final int MAJOR_POSITION = 12;
    private static final int FOREIGN_CLASS_POSITION = 13;
    private static final int POLITESTATE_POSITION = 14;
    private static final int SOCIAL_NUM_POSITION = 15;
    private static final int SKILL_POSITION = 16;
    private static final int INTRESTS_POSITION = 17;
    private static final int QQ_POSITION = 18;
    private static final int WECHAT_POSITION = 19;
    private String key;
    private String value;
    private boolean isUpdate;
    private ActionSheetDialog chooseDialogZiyezhige;
    private ActionSheetDialog chooseDialogHunyin;

    private MineAuPerfectActivityCustom dataBinding;
    private String[] titles = new String[]{
            "身高(cm)",
            "体重(kg)",
            "血型",
            "生肖",
            "信仰",
            "现住址",
            "婚否",
            "紧急联系人姓名",
            "紧急联系人关系",
            "紧急联系人电话",
            "毕业院校",
            "学历",
            "职业资格",
            "外语等级",
            "政治面貌",
            "社会保险号",
            "所学专业",
            "兴趣爱好（可选）",
            "QQ（可选）",
            "微信（可选）"
    };
    private String[] titleTexts = new String[]{
            "身高(cm)",
            "体重(kg)",
            "血型",
            "生肖",
            "信仰",
            "现住址",
            "婚否",
            "紧急联系人姓名",
            "紧急联系人关系",
            "紧急联系人电话",
            "毕业院校",
            "学历",
            "职业资格",
            "外语等级",
            "政治面貌",
            "社会保险号",
            "所学专业",
            "兴趣爱好（可选）",
            "QQ（可选）",
            "微信（可选）"
    };
    private String[] hintTexts = new String[]{
            "请输入",
            "请输入",
            "请选择",
            "请输入",
            "请输入",
            "请选择",
            "请选择",
            "请输入",
            "请输入",
            "请输入",
            "请选择",
            "请输入",
            "请输入",
            "请选择",
            "请选择",
            "请输入",
            "请选择",
            "请输入",
            "请输入",
            "请输入"
    };
    private String[] tipTexts = new String[]{
            "身高(cm)",
            "体重(kg)",
            "血型",
            "生肖",
            "信仰",
            "现住址",
            "婚否",
            "紧急联系人姓名",
            "紧急联系人关系",
            "紧急联系人电话",
            "毕业院校",
            "学历",
            "职业资格",
            "外语等级",
            "政治面貌",
            "社会保险号",
            "所学专业",
            "兴趣爱好（可选）",
            "QQ（可选）",
            "微信（可选）"
    };
    private int[] types = new int[]{
            0, 0, 1, 4, 4, 4, 4, 0, 4, 0,
            0, 4, 4, 4, 4, 0, 0, 0, 0, 0
    };
    private BottomDialog areaDialog;

    private int[] decoders = new int[]{20};
    private HashMap<Integer, String> params;
    private List<AreaBean> areaBean;
    private String result;
    private ActionSheetDialog chooseDialogWenhuachengdu;
    private ActionSheetDialog chooseDialogZhengzhi;
    private String msg;
    private HashMap<Integer, String> tipMap;
    private InvitedListResultBean comInviteBean;
    private ActionSheetDialog chooseDialogBelief;
    private ActionSheetDialog chooseDialogRelate;
    private ActionSheetDialog chooseDialogForeign;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_mine_au_perfect);
        initTopTitleBar(View.VISIBLE, "完善信息");
        initTopRightText("提交", v -> {
            if (checkInfo()) {
                if (comInviteBean != null) {
                    OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.JOIN_COM)
                            .params("userGuid", user.getGuid())
                            .params("user", user.getUname())
                            .params("entryId", comInviteBean.getId())
                            .execute(new DialogCallBack<HttpResult>(this) {
                                @Override
                                public void onSuccess(Response<HttpResult> response) {
                                    HttpResult httpResult = response.body();
                                    ToastUtil.showShort(httpResult.getMsg());
                                    if (httpResult.getStatus() == 200) {
                                        startService(new Intent(MineAuPerfectActivity.this, UserService.class));
                                        setResult(Config.SUCCESS);
                                        finish();
                                    }
                                }
                            });
                }
            } else {
                ToastUtil.showShort(msg);
            }
        });
    }

    private boolean checkInfo() {

        Iterator<Map.Entry<Integer, String>> iterator = tipMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, String> next = iterator.next();
            if (TextUtils.isEmpty(quickAdapter.getItem(next.getKey()).getContent()) || "0".equals(quickAdapter.getItem(next.getKey()).getContent())) {
                msg = next.getValue();
                return false;
            }
        }
        return true;
    }

    @Override
    public void initData() {
        comInviteBean = getIntent().getParcelableExtra(Config.COM_INVITE_INFO);
        refreshData();
        ArrayList<Scheme> schemes;
        for (int i = 0; i < titles.length; i++) {
            EditBean editBean = new EditBean();
            editBean.setTitle(titles[i]);
            editBean.setType(types[i]);
            editBean.setContent("");
            editBean.setTextTip(tipTexts[i]);
            editBean.setTextTitle(titleTexts[i]);
            if (types[i] == EditBean.TITLE) {
                editBean.setShowTopTitle(true);
                editBean.setTopTitle(titles[i]);
            }
            switch (i) {
                case HEIGHT_POSITION://身高
                    schemes = new ArrayList<>();
                    schemes.add(StaticScheme.Digits());
                    schemes.add(ValueScheme.RangeLength(2, 3));
                    editBean.setSchemes(schemes);
                    break;
                case WEIGH_POSITION://体重
                    schemes = new ArrayList<>();
                    schemes.add(StaticScheme.Digits());
                    schemes.add(ValueScheme.RangeLength(2, 3));
                    editBean.setSchemes(schemes);
                case BLOOD_POSITION://血型
                    editBean.setChooseItem(getResources().getStringArray(R.array.blood));
                    break;
                case QQ_POSITION://qq
                    schemes = new ArrayList<>();
                    schemes.add(StaticScheme.Digits());
                    schemes.add(ValueScheme.MaxLength(12));
                    editBean.setSchemes(schemes);
                    break;
                case WECHAT_POSITION://微信
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;
                case CONTRACT_NAME_POSITION://紧急联系人
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;
                case CONTRACT_REALT_POSITION://紧急联系人关系
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;
                case CONTRACT_TEL_POSITION://紧急联系人电话
                    schemes = new ArrayList<>();
                    schemes.add(StaticScheme.ChineseMobile());
                    editBean.setSchemes(schemes);
                    break;
                case GRAD_POSITION://毕业院校
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;
                case SKILL_POSITION://所学专业
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;
                case FOREIGN_CLASS_POSITION://外语等级
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;
                case SOCIAL_NUM_POSITION://社会保险号
                    schemes = new ArrayList<>();
                    editBean.setSchemes(schemes);
                    break;

            }
            editBeans.add(editBean);
        }
        params = new HashMap<>();
        params.put(HEIGHT_POSITION, "uheigh");
        params.put(WEIGH_POSITION, "uweigh");
        params.put(BLOOD_POSITION, "ublood");
        params.put(CZODIA_POSITION, "uczodia");
        params.put(BELIEF_POSITION, "ubelief");
        params.put(POLITESTATE_POSITION, "upoliticstate");
        params.put(INTRESTS_POSITION, "uinterest");
        params.put(ADRESS_POSITION, "upadress");
        params.put(MARRY_POSITION, "umarry");
        params.put(CONTRACT_NAME_POSITION, "ucontactname");
        params.put(CONTRACT_TEL_POSITION, "uscontact");
        params.put(CONTRACT_REALT_POSITION, "uscontactrelat");
        params.put(QQ_POSITION, "uqq");
        params.put(WECHAT_POSITION, "uwchat");
        params.put(GRAD_POSITION, "ugrad");
        params.put(EDU_POSITION, "uedu");
        params.put(SKILL_POSITION, "upskill");
        params.put(MAJOR_POSITION, "umajor");
        params.put(FOREIGN_CLASS_POSITION, "uforeignclass");
        params.put(SOCIAL_NUM_POSITION, "usocialsecuritynum");
        tipMap = new HashMap<>();
        tipMap.put(HEIGHT_POSITION, "请认真填写身高");
        tipMap.put(WEIGH_POSITION, "请认真填写体重");
        tipMap.put(BLOOD_POSITION, "请选择血型");
        tipMap.put(CZODIA_POSITION, "个人实名认证未成功");
        tipMap.put(BELIEF_POSITION, "请认真填写信仰");
        tipMap.put(POLITESTATE_POSITION, "请选择政治面貌");
        tipMap.put(ADRESS_POSITION, "请选择地址");
        tipMap.put(MARRY_POSITION, "请选择婚姻状况");
        tipMap.put(CONTRACT_NAME_POSITION, "请认真填写紧急联系人姓名");
        tipMap.put(CONTRACT_TEL_POSITION, "请认真填写紧急联系人电话");
        tipMap.put(CONTRACT_REALT_POSITION, "请认真填写紧急联系人关系");
        tipMap.put(GRAD_POSITION, "请认真填写毕业院校");
        tipMap.put(EDU_POSITION, "请选择学历");
        tipMap.put(SKILL_POSITION, "请填写所学专业");
        tipMap.put(MAJOR_POSITION, "请选择职业资格");
        tipMap.put(FOREIGN_CLASS_POSITION, "请填写外语等级");
//        tipMap.put(SOCIAL_NUM_POSITION, "请填写社会保险号");
    }

    private void refreshData() {
        OkGo.<HttpResult<UserAuthInfoResultBean>>post(HttpConfig.BASE_URL + HttpConfig.GET_USER_ALL_INFO)
                .params("userGuid", user.getGuid())
                .params("password", EncryptUtil.sha1(SPUtil.getParam(Config.PASS, "") + "EQD"))
                .execute(new DialogCallBack<HttpResult<UserAuthInfoResultBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpResult<UserAuthInfoResultBean>> response) {
                        HttpResult<UserAuthInfoResultBean> httpResult = response.body();
                        if (httpResult.getStatus() == 200) {
                            updateView(httpResult.getItems());
//                            Bundle bundle = new Bundle();
//                            bundle.putSerializable(Config.USER_AUTH_INFO, httpResult.getItems());
//                            startActivityForResult(UserDocumentActivity.class, bundle, Config.USER_DOCUMENT);
                        } else if (httpResult.getStatus() == 202) {
                            ToastUtil.showShort(httpResult.getMsg());
                        } else if (httpResult.getStatus() == 500) {
                            AlterDialogFragment alterDialogFragment = AlterDialogFragment.newInstance("提示", "你还未实名认证，是否实名认证", "取消", "确定");
                            alterDialogFragment.setOnAlterDialogBtnListener(new AlterDialogFragment.AlterDialogBtnListener() {
                                @Override
                                public void onDialogPositiveClick(AlterDialogFragment alterDialogFragment) {
                                    startActivityForResult(MineAuActivity.class, null, Config.MINE_AU);
                                }

                                @Override
                                public void onDialogNegativeClick(AlterDialogFragment alterDialogFragment) {
                                    alterDialogFragment.dismiss();
                                    finish();
                                }
                            });
                            alterDialogFragment.show(getSupportFragmentManager());
                        }
                    }

                });
    }

    private void updateView(UserAuthInfoResultBean userInfoBean) {

        editBeans.get(HEIGHT_POSITION).setContent(userInfoBean.getUheigh() + "");
        editBeans.get(WEIGH_POSITION).setContent(userInfoBean.getUweigh() + "");
        editBeans.get(BLOOD_POSITION).setContent(userInfoBean.getUblood() + "");
        String date = userInfoBean.getUdate();
        SimpleDateFormat sf;
        try {
            sf = new SimpleDateFormat("yyyy-MM-dd");
            Date parse = sf.parse(date);
            Calendar instance = Calendar.getInstance();
            instance.setTime(parse);
            int year = instance.get(Calendar.YEAR);
            int shenxiao = (year + 8) % 12;
            String[] stringArray = getResources().getStringArray(R.array.zodiac);
            editBeans.get(CZODIA_POSITION).setContent(stringArray[shenxiao]);
        } catch (Exception e) {
            editBeans.get(CZODIA_POSITION).setContent("未填写");
        }
        editBeans.get(BELIEF_POSITION).setContent(userInfoBean.getUbelief());
        editBeans.get(POLITESTATE_POSITION).setContent(userInfoBean.getUpoliticstate());
        editBeans.get(INTRESTS_POSITION).setContent(userInfoBean.getUinterest());
        editBeans.get(ADRESS_POSITION).setContent(userInfoBean.getUpadress());
        editBeans.get(MARRY_POSITION).setContent(userInfoBean.getUmarry());
        editBeans.get(CONTRACT_NAME_POSITION).setContent(userInfoBean.getUcontactname());
        editBeans.get(CONTRACT_TEL_POSITION).setContent(userInfoBean.getUscontact());
        editBeans.get(CONTRACT_REALT_POSITION).setContent(userInfoBean.getUscontactrelat());
        editBeans.get(QQ_POSITION).setContent(userInfoBean.getUqq());
        editBeans.get(WECHAT_POSITION).setContent(userInfoBean.getUwchat());
        editBeans.get(GRAD_POSITION).setContent(userInfoBean.getUgrad());
        editBeans.get(EDU_POSITION).setContent(userInfoBean.getUedu());
        editBeans.get(MAJOR_POSITION).setContent(userInfoBean.getUmajor());
        editBeans.get(SKILL_POSITION).setContent(userInfoBean.getUpskill());
        editBeans.get(FOREIGN_CLASS_POSITION).setContent(userInfoBean.getUforeignclass());
        editBeans.get(SOCIAL_NUM_POSITION).setContent(userInfoBean.getUsocialsecuritynum());
        if (quickAdapter != null) {
            quickAdapter.notifyDataSetChanged();
        }
    }

    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {
        switch (p) {
            case ADRESS_POSITION://现住址
                if (areaDialog == null) {
                    initAreaDialog();
                } else {
                    areaDialog.show();
                }
                break;
            case CONTRACT_REALT_POSITION://关系
                if (chooseDialogRelate == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 23, (sheet) -> {
                        chooseDialogRelate = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(CONTRACT_REALT_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(CONTRACT_REALT_POSITION);
                        key = params.get(CONTRACT_REALT_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogRelate.show();
                }
                break;
            case FOREIGN_CLASS_POSITION://关系
                if (chooseDialogForeign == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 24, (sheet) -> {
                        chooseDialogForeign = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(FOREIGN_CLASS_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(FOREIGN_CLASS_POSITION);
                        key = params.get(FOREIGN_CLASS_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogForeign.show();
                }
                break;
            case BELIEF_POSITION://信仰
                if (chooseDialogBelief == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 25, (sheet) -> {
                        chooseDialogBelief = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(BELIEF_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(BELIEF_POSITION);
                        key = params.get(BELIEF_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogBelief.show();
                }
                break;
            case MARRY_POSITION:
                if (chooseDialogHunyin == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 22, (sheet) -> {
                        chooseDialogHunyin = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(MARRY_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(MARRY_POSITION);
                        key = params.get(MARRY_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogHunyin.show();
                }
                break;
            case POLITESTATE_POSITION://政治面貌
                if (chooseDialogZhengzhi == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 15, (sheet) -> {
                        chooseDialogZhengzhi = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(POLITESTATE_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(POLITESTATE_POSITION);
                        key = params.get(POLITESTATE_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogZhengzhi.show();
                }
                break;
            case EDU_POSITION://文化程度
                if (chooseDialogWenhuachengdu == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 10, (sheet) -> {
                        chooseDialogWenhuachengdu = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(EDU_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(EDU_POSITION);
                        key = params.get(EDU_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogWenhuachengdu.show();
                }
                break;
            case MAJOR_POSITION://职业资格
                if (chooseDialogZiyezhige == null) {
                    SingleChooseUtil.getChooseDialog(MineAuPerfectActivity.this, 16, (sheet) -> {
                        chooseDialogZiyezhige = sheet;
                        sheet.show();
                    }, (position, strings) -> {
                        editBeans.get(MAJOR_POSITION).setContent(strings.get(position - 1));
                        quickAdapter.notifyItemChanged(MAJOR_POSITION);
                        key = params.get(MAJOR_POSITION);
                        value = strings.get(position - 1);
                        isUpdate = true;
                        updateUserInfo();
                    });
                } else {
                    chooseDialogZiyezhige.show();
                }
                break;
        }
    }

    private void initAreaDialog() {
        OkGo.<List<AreaBean>>get(HttpConfig.BASE_URL + HttpConfig.AREA_OPTIONS)
                .cacheKey(HttpConfig.BASE_URL + HttpConfig.AREA_OPTIONS + "0")
                .params("type", 0)
                .cacheMode(CacheMode.IF_NONE_CACHE_REQUEST)
                .execute(new JsonCallBack<List<AreaBean>>() {
                    @Override
                    public void onSuccess(Response<List<AreaBean>> response) {
                        System.out.println("使用了网络");

                        areaBean = response.body();
                        areaDialog = new MultiChooseUtil().getAreaDialog(MineAuPerfectActivity.this, 3, areaBean, (d, a) -> {
                            areaDialog.dismiss();
                            result = "";
                            for (ISelectAble iSelectAble : a) {
                                result += iSelectAble.getName();
                            }
                            editBeans.get(ADRESS_POSITION).setContent(result);
                            quickAdapter.notifyItemChanged(ADRESS_POSITION);
                            EditDialogFragment editDiglog = ChooseAlertView.getEditDiglog("请输入详细地址", "详细地址", null, contents -> {
                                editBeans.get(ADRESS_POSITION).setContent(result + contents.get(0));
                                quickAdapter.notifyItemChanged(ADRESS_POSITION);
                                key = params.get(ADRESS_POSITION);
                                value = result + contents.get(0);
                                isUpdate = true;
                                updateUserInfo();
                            });
                            editDiglog.show(getSupportFragmentManager(), "edit");
                        });
                        areaDialog.show();
                    }

                    @Override
                    public void onCacheSuccess(Response<List<AreaBean>> response) {
                        super.onCacheSuccess(response);
                        System.out.println("使用了缓存");
                        areaBean = response.body();
                        areaDialog = new MultiChooseUtil().getAreaDialog(MineAuPerfectActivity.this, 3, areaBean, (d, a) -> {
                            areaDialog.dismiss();
                            result = "";
                            for (ISelectAble iSelectAble : a) {
                                result += iSelectAble.getName();
                            }
                            editBeans.get(ADRESS_POSITION).setContent(result);
                            quickAdapter.notifyItemChanged(ADRESS_POSITION);
                            EditDialogFragment editDiglog = ChooseAlertView.getEditDiglog("请输入详细地址", "详细地址", null, contents -> {
                                editBeans.get(ADRESS_POSITION).setContent(result + contents.get(0));
                                quickAdapter.notifyItemChanged(ADRESS_POSITION);
                                key = params.get(ADRESS_POSITION);
                                value = result + contents.get(0);
                                isUpdate = true;
                                updateUserInfo();
                            });
                            editDiglog.show(getSupportFragmentManager(), "edit");
                        });
                        areaDialog.show();
                    }
                });


    }

    private void updateUserInfo() {
        if (isUpdate) {
            OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.UPDATE_USER_INFO)
                    .params("userGuid", user.getGuid())
                    .params("para", key + "='" + value + "'")
                    .execute(new DialogCallBack<HttpResult>(this) {
                        @Override
                        public void onSuccess(Response<HttpResult> response) {
                            HttpResult httpResult = response.body();
                            ToastUtil.showShort(httpResult.getMsg());
                        }
                    });
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        key = null;
        value = null;
        isUpdate = false;
        if (resultCode == Config.INTENT_CONTENT) {
            value = data.getStringExtra("content");
            isUpdate = true;
            key = params.get(requestCode);
            updateUserInfo();
        }
        if (requestCode == Config.MINE_AU) {
            refreshData();
        }
    }

    @Override
    public void onChooseClick(int position) {
        System.out.println(position);
        key = null;
        value = null;
        isUpdate = false;
        if (clicked == BLOOD_POSITION) {
            key = "ublood";
            value = getResources().getStringArray(R.array.blood)[position - 1];
            isUpdate = true;
            updateUserInfo();
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }
}
